home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / packet / p_aa4re / bb212src / bbauxmnr.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-01-18  |  9.1 KB  |  267 lines

  1. (*===========================================================================*)
  2. (* Monitored frame - NETROM                                                  *)
  3. (*                                                                           *)
  4. (*   Copyright 1988, 1990, 1991 by H. Roy Engehausen.  All rights reserved.  *)
  5. (*                                                                           *)
  6. (*===========================================================================*)
  7.  
  8. (*===========================================================================*)
  9. (* Monitor a channel                                                         *)
  10. (*===========================================================================*)
  11.  
  12. PROCEDURE netrom_monitor(in_ptr     : str_mixed_ptr;
  13.                          in_off     : WORD;
  14.                          nodes_bcst : BOOLEAN);
  15.  
  16.   TYPE
  17.  
  18.     ax25_call      = RECORD
  19.                        call_sign : ARRAY[1..6] OF BYTE;
  20.                        ssid      : BYTE;
  21.                      END;
  22.  
  23.     ax25_call_ptr  = ^ax25_call;
  24.  
  25.     netrom_header  = RECORD
  26.                        call_1 : ax25_call;
  27.                        call_2 : ax25_call;
  28.                        t_to_l : BYTE;
  29.                        cindex : BYTE;
  30.                        cid    : BYTE;
  31.                        data_1 : BYTE;
  32.                        data_2 : BYTE;
  33.                        opflag : BYTE;
  34.                        cdata  : ARRAY[1..20] OF CHAR;
  35.                      END;
  36.  
  37.     netrom_header_ptr = ^netrom_header;
  38.  
  39.   CONST
  40.     nr_choke    = $80;
  41.     nr_nak      = $40;
  42.     nr_more     = $20;
  43.     nr_reserve  = $10;
  44.     nr_opcode   = $0F;
  45.  
  46.   VAR
  47.     b           : BOOLEAN;
  48.     nr_code     : BYTE;
  49.     nr_code_str : STRING[8];
  50.     nr_ptr      : ^netrom_header;
  51.     out_string  : STRING;
  52.     out_off     : WORD;
  53.     t           : str_mixed;
  54.  
  55.   {$I BBAUXMNA.PAS} (* AX25 to call    *)
  56.   {$I BBAUXMNB.PAS} (* Nodes Broadcast *)
  57.  
  58.   BEGIN;
  59.  
  60.     (*-----------------------------------------------------------------------*)
  61.     (* If this is a nodes broadcast then handle that special                 *)
  62.     (*-----------------------------------------------------------------------*)
  63.  
  64.     IF nodes_bcst THEN
  65.       BEGIN;
  66.         do_nodes_bcst;
  67.         EXIT;
  68.       END;
  69.  
  70.     (*-----------------------------------------------------------------------*)
  71.     (* Compute start of input data and output data                           *)
  72.     (*-----------------------------------------------------------------------*)
  73.  
  74.     nr_ptr := @in_ptr^.long_data[in_off];
  75.  
  76.     out_off := in_off + 20;
  77.  
  78.     WITH nr_ptr^, in_ptr^ DO
  79.       BEGIN;
  80.  
  81.         (*-------------------------------------------------------------------*)
  82.         (* Decipher the to call and from call along with connect #s          *)
  83.         (*-------------------------------------------------------------------*)
  84.  
  85.         out_string := '(' + ax25_call_to_string(@call_1) + ' > ' +
  86.                             ax25_call_to_string(@call_2) + ', ' +
  87.                             b2x(t_to_l) + ', ' +
  88.                             b2x(cindex) + '/' +
  89.                             b2x(cid) + ' [';
  90.  
  91.         (*-------------------------------------------------------------------*)
  92.         (* get the netrom opcode and decipher that                           *)
  93.         (*-------------------------------------------------------------------*)
  94.  
  95.         nr_code := opflag AND nr_opcode;
  96.  
  97.         CASE nr_code OF
  98.           1 : nr_code_str := 'CR';
  99.           2 : nr_code_str := 'CA';
  100.           3 : nr_code_str := 'DR';
  101.           4 : nr_code_str := 'DA';
  102.           5 : nr_code_str := 'IF';
  103.           6 : nr_code_str := 'IA';
  104.           ELSE
  105.             nr_code_str := '??';
  106.         END;
  107.  
  108.         (*-------------------------------------------------------------------*)
  109.         (* Decipher flags                                                    *)
  110.         (*-------------------------------------------------------------------*)
  111.  
  112.         i := opflag AND nr_choke;
  113.         IF i <> 0 THEN
  114.           nr_code_str := nr_code_str + '-C';
  115.  
  116.         i := opflag AND nr_nak;
  117.         IF i <> 0 THEN
  118.           nr_code_str := nr_code_str + '-N';
  119.  
  120.         i := opflag AND nr_more;
  121.         IF i <> 0 THEN
  122.           nr_code_str := nr_code_str + '-M';
  123.  
  124.         (*-------------------------------------------------------------------*)
  125.         (* Build more output string                                          *)
  126.         (*-------------------------------------------------------------------*)
  127.  
  128.         out_string := out_string + nr_code_str;
  129.  
  130.         (*-------------------------------------------------------------------*)
  131.         (* More special deciphering based on the netrom code                 *)
  132.         (*-------------------------------------------------------------------*)
  133.  
  134.         b := TRUE;
  135.  
  136.         CASE nr_code OF
  137.  
  138.           1: BEGIN; (* CR *)
  139.  
  140.                out_string := out_string + ']: ' +
  141.                              ax25_call_to_string(@cdata[2]) + '@' +
  142.                              ax25_call_to_string(@cdata[9]) + ' ' +
  143.                              w2c(ORD(cdata[1]));
  144.                INC(out_off, 16);
  145.                b := FALSE;
  146.              END;
  147.  
  148.           2: BEGIN; (* CA *)
  149.                out_string := out_string + ']: ' + w2c(ORD(cdata[1]));
  150.                INC(out_off, 2);
  151.                b := FALSE;
  152.              END;
  153.  
  154.           5: BEGIN; (* IF *)
  155.                out_string := out_string + ', ' + w2c(data_1) + ', ' +
  156.                                                  w2c(data_2);
  157.              END;
  158.  
  159.           6: BEGIN; (* IA *)
  160.                out_string := out_string + ', ' + w2c(data_2);
  161.              END;
  162.  
  163.         END;
  164.  
  165.         (*-------------------------------------------------------------------*)
  166.         (* If b is true then end in a bracket else end in just paren         *)
  167.         (*-------------------------------------------------------------------*)
  168.  
  169.         IF b THEN
  170.           BEGIN;
  171.             IF long_length >= out_off THEN
  172.               out_string := out_string + '])'
  173.             ELSE
  174.               out_string := out_string + ']):';
  175.           END
  176.         ELSE
  177.           BEGIN;
  178.             IF long_length >= out_off THEN
  179.               out_string := out_string + ') -- '
  180.             ELSE
  181.               out_string := out_string + ')';
  182.           END;
  183.  
  184.         (*-------------------------------------------------------------------*)
  185.         (* If anything left on input line and we are not in a data frame,    *)
  186.         (* please display it in hex                                          *)
  187.         (*-------------------------------------------------------------------*)
  188.  
  189.         IF (long_length >= out_off) AND (nr_code <> 5) THEN
  190.           BEGIN;
  191.            i := 0;
  192.            WHILE (long_length >= out_off) AND (i < 8) DO
  193.              BEGIN;
  194.                out_string := out_string + b2x(ORD(in_ptr^.str_data[out_off-1]));
  195.                INC(out_off);
  196.                INC(i);
  197.              END;
  198.           END;
  199.  
  200.         (*-------------------------------------------------------------------*)
  201.         (* Put CR on the line.  Thats the end of the NETROM data             *)
  202.         (*-------------------------------------------------------------------*)
  203.  
  204.         out_string := out_string + cr;
  205.  
  206.         (*-------------------------------------------------------------------*)
  207.         (* Now start building the l_string output                            *)
  208.         (*-------------------------------------------------------------------*)
  209.  
  210.         IF in_off = 1 THEN
  211.           WITH t DO
  212.             BEGIN;
  213.               long_length := 0;
  214.               str_data    := '';
  215.             END
  216.         ELSE
  217.           t := l_substr(in_ptr, 1, in_off-1)^;
  218.  
  219.         (*-------------------------------------------------------------------*)
  220.         (* Put the NETROM header info in the output buffer                   *)
  221.         (*-------------------------------------------------------------------*)
  222.  
  223.         l_cat_str(@t, out_string);
  224.  
  225.         (*-------------------------------------------------------------------*)
  226.         (* See if anything left for the output buffer from the input buffer  *)
  227.         (* Move as need be                                                   *)
  228.         (*-------------------------------------------------------------------*)
  229.  
  230.         IF long_length > out_off THEN
  231.           l_cat(@t, l_substr(in_ptr, out_off, 0));
  232.  
  233.         (*-------------------------------------------------------------------*)
  234.         (* Put the output in the proper place                                *)
  235.         (*-------------------------------------------------------------------*)
  236.  
  237.         in_ptr^ := t;
  238.  
  239.       END;
  240.  
  241.   END;
  242.  
  243. PROCEDURE netrom_monitor_232;
  244.  
  245.   VAR
  246.     i : WORD;
  247.     j : WORD;
  248.  
  249.   BEGIN;
  250.  
  251.     i := l_pos(@in_1, cr);
  252.  
  253.     IF (i < 4) OR (i > 255) THEN
  254.       EXIT;
  255.  
  256.     IF substr(in_1.str_data, i-3, 3) <> 'CF:' THEN
  257.       EXIT;
  258.  
  259.     j := l_pos(@in_1, '>');
  260.  
  261.     IF (j < 1) OR (j > 249) THEN
  262.       EXIT;
  263.  
  264.     netrom_monitor(@in_1, i + 1, substr(in_1.str_data, j + 1, 6) = 'NODES ');
  265.  
  266.   END;
  267.